/**
 * @date 2022/4/1
 * @description store配置
 * @author 
 *
 * 参考：https://vitejs.dev/guide/features.html#glob-import
 *
 */

import { createStore } from "vuex";
import getters from "./getters.js";

//Glob 导入
const modulesFiles =
    import.meta.globEager("./modules/*.js");

let modules = {};

for (const path in modulesFiles) {
    //获取模块名字
    const moduleName = path.replace(/(.*\/)*([^.]+).*/gi, "$2");
    modules[moduleName] = modulesFiles[path].default;
}
Object.keys(modules).forEach((key) => {
    modules[key]["namespaced"] = true;
});

const store = new createStore({
    modules,
    getters,
});

export default store;